const app 		= getApp(),
	  api 		= require("../../../utils/api.js"),
	  request 	= require("../../../service/request.js");

Page({
	data:{
		ruisiDetail:{}
	},
	onLoad:function (params){
		var that = this,
			sessionid = app.globalData.sessionid;
		request.get(`${api.getDetail}?infoid=${params.id}`, {}, sessionid).then(res => {
			console.log(res.data);
			res.data.isfavorited ? that.setData({scIcon : "icon-shoucang",ruisiDetail:res.data}) : 
									that.setData({scIcon : "icon-shoucang2",ruisiDetail:res.data});
		});
	},
	shoucang:function(){
		var that = this;
		console.log("点了收藏");
		if(this.data.scIcon=="icon-shoucang2"){
			var favoritesnum = that.data.ruisiDetail.favoritesnum + 1;
			this.setData({
				scIcon : "icon-shoucang",
				"ruisiDetail.favoritesnum": favoritesnum
			})
		}else{
			var favoritesnum = that.data.ruisiDetail.favoritesnum - 1;
			this.setData({
				scIcon : "icon-shoucang2",
				"ruisiDetail.favoritesnum": favoritesnum
			})
		}
		request.get(`${api.collect}&infoid=${that.data.ruisiDetail.infoid}`, {}, app.globalData.sessionid).then(res => {
			console.log(res.data);
		});
	}
});